// 测试环境设置文件

// 模拟localStorage
const localStorageMock = (() => {
  let store = {}
  return {
    getItem: jest.fn(key => store[key] || null),
    setItem: jest.fn((key, value) => {
      store[key] = value.toString()
    }),
    removeItem: jest.fn(key => {
      delete store[key]
    }),
    clear: jest.fn(() => {
      store = {}
    })
  }
})()

// 模拟sessionStorage
const sessionStorageMock = {
  getItem: jest.fn(),
  setItem: jest.fn(),
  clear: jest.fn(),
  removeItem: jest.fn()
}

// 模拟window对象
Object.defineProperty(window, 'localStorage', {
  value: localStorageMock
})

Object.defineProperty(window, 'sessionStorage', {
  value: sessionStorageMock
})

// 模拟document对象方法
global.document = {
  createElement: jest.fn(() => ({
    style: {},
    setAttribute: jest.fn(),
    appendChild: jest.fn(),
    removeChild: jest.fn()
  })),
  querySelector: jest.fn(),
  addEventListener: jest.fn(),
  removeEventListener: jest.fn()
}

// 模拟navigator对象
global.navigator = {
  userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}

// 模拟axios（如果需要）
global.axios = {
  get: jest.fn(),
  post: jest.fn(),
  put: jest.fn(),
  delete: jest.fn()
}

// 清理所有mock
jest.clearAllMocks()